home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11591 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: solon.com!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated,hp.unix,comp.sys.hp.apps,comp.sys.hp.hpux
  4. Subject: Re: C coding problem
  5. Date: 25 Mar 1996 06:26:52 -0600
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4j63ec$3l7@solutions.solon.com>
  10. References: <4ianbf$h86@solutions.solon.com> <4iemcl$a05@solutions.solon.com> <4io1io$no4@solutions.solon.com> <4j06na$808@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12.  
  13. In article <4j06na$808@solutions.solon.com>,
  14. Gary Quakenbush <garyq@hpfcla.fc.hp.com> wrote:
  15.  >Konrad Schwarz (schwarz@mips.complang.tuwien.ac.at) wrote:
  16.  >: One of C's most defining attributes is the pointer concept
  17.  >: which includes the mapping of arrays to pointer arithmetic.  If you're
  18.  >: going to fight it, it might be better to switch to some other programming
  19.  >: language.
  20.  >
  21.  >: I recently wrote a loop that went like this:
  22.  >
  23.  >: while (p < end_p)
  24.  >:     ++*p++;
  25.  >
  26.  >: Maybe some will find it a counter-example; I think it's good
  27.  >: code that embodies the way C is designed to work.  Arrays are
  28.  >: second rate objects in C.  Use pointers.
  29.  >
  30.  >Ok, I'll bite.
  31.  >
  32.  >This could be useful as an interview question.
  33.  >
  34.  >Interviewee gets points for quickly locating in C reference the info
  35.  >needed to understand this.
  36.  
  37. Interviewee should know this if he or she purports to be a C programmer,
  38. without needing a reference.
  39.  
  40. The precedence and associativity of the language is such that the p++ is parsed
  41. first. The value of p is noted, and p is then incremented. This noted value is
  42. then dereferenced, and the object previously pointed at by p is incremented.
  43. The * and ++ operators have the same precedence.
  44.  
  45.  >Interviewee gets extra points for mentioning maintainability tradeoffs.
  46.  
  47. I wouldn't mention any such thing. It's a perfectly unambigous and maintainable
  48. statement.
  49.  
  50.  >Interviewee gets hired if she rewrites to be trivial for "contractor of
  51.  >the month" to understand and maintain.
  52.  
  53. I'd suggest extra parentheses:
  54.  
  55.      ++*(p++);
  56. -- 
  57.